package com.mrduan.otgfilemanager;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.mob.MobSDK;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

import org.xutils.x;

import java.util.Calendar;

/**
 * Created by snoopy on 2018/4/28.
 */

public class App extends Application {
    public static int SCREEN_WIDTH, SCREEN_HEIGHT;

    public static String VERSION;

    public static int Day_Of_Week;
    public static String shareKey;

    public static final String APP_ID = "wx8a1a4102dd8674a5";

    @Override
    public void onCreate() {
        super.onCreate();
        screenSize();

        MobSDK.init(this);

        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.

        VERSION = getVersionName(this);

        Logger.addLogAdapter(new AndroidLogAdapter());

        getDayOfWeek();


    }

    private void screenSize() {
        Resources resources = this.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        float density = dm.density;
        SCREEN_WIDTH = dm.widthPixels;
        SCREEN_HEIGHT = dm.heightPixels;
    }

    /**
     * get App versionName
     *
     * @param context
     * @return
     */
    public String getVersionName(Context context) {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo;
        String versionName = "";
        try {
            packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }

    public void getDayOfWeek() {
        int[] day = {7, 1, 2, 3, 4, 5, 6};
        Day_Of_Week = day[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1];
        shareKey = "share" + day[Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1];
    }

}
